﻿/*
NAILSUPERSTORE ® COMPANY
 
[HISTORY]
Created By  	: NGUYEN VAN TY
Created Date	: 12/01/2010
Modified By     :
Modified Date   :
Note            :

*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CommonTagTime.DataAccess;
using CommonTagTime.ModelObject;
namespace CommonTagTime.Business
{
    public class busCategory
    {
        //------------------------------------------------
        //FIELD TABLE
        //------------------------------------------------
        public const string TABLE = "Category";
        public const string CATEGORYID = "CategoryID";
        public const string PARENTID = "ParentId";
        public const string LEVEL = "Level";
        public const string SORTORDER = "SortOrder";
        public const string ISACTIVE = "IsActive";
        public const string NAME = "Name";
        public const string DESCRIPTION = "Description";
        public const string MetaKeywords = "MetaKeywords";
        public const string MetaDescription = "MetaDescription";
        public const string PageTitle = "PageTitle";
        public const string Type = "Type";
        public const string CREATEDBY = "CreatedBy";
        public const string CREATEDDATE = "CreatedDate";
        public const string UPDATEDBY = "UpdatedBy";
        public const string UPDATEDDATE = "UpdatedDate";
        public const string ORDERBY = "OrderBy";
        public const string ORDERDIRECTION = "OrderDirection";
        public const string CURRENTPAGE = "CurrentPage";
        public const string PAGESIZE = "PageSize";
        public const string TOTALRECORDS = "TotalRecords";
        public const string CONDITION = "Condition";


        private daoCategory _daoProduct;
        //------------------------------------------------
        //PUBLIC
        //------------------------------------------------
        public busCategory()
        {
            _daoProduct = new daoCategory();
        }
        public CategoryCollection List(Category _category)
        {
            return _daoProduct.List(_category);
        }
        public bool OrderDown(int _categoryID)
        {
            bool result = _daoProduct.OrderDown(_categoryID);
            if (result)
                clsCacheUtil.RemoveCacheWithPrefix("Category_");
            return result;
        }
        public bool OrderUp(int _categoryID)
        {
            bool result = _daoProduct.OrderUp(_categoryID);
            if (result)
                clsCacheUtil.RemoveCacheWithPrefix("Category_");
            return result;
        }
        public bool Active(int _categoryID)
        {
            bool result = _daoProduct.Active(_categoryID);
            if (result)
                clsCacheUtil.RemoveCacheWithPrefix("Category_");
            return result;
        }
        public bool DeActive(int _categoryID)
        {
            bool result = _daoProduct.DeActive(_categoryID);
            if (result)
                clsCacheUtil.RemoveCacheWithPrefix("Category_");
            return result;
        }
        public bool Delete(int _categoryID)
        {
            bool result = _daoProduct.Delete(_categoryID);
            if (result)
                clsCacheUtil.RemoveCacheWithPrefix("Category_");
            return result;
        }
        public void DeleteMulti(CategoryCollection lstCategory)
        {
            foreach (Category objCate in lstCategory)
            {
                _daoProduct.Delete(objCate.CategoryID);
            }
            clsCacheUtil.RemoveCacheWithPrefix("Category_");
        }
        public bool Insert(Category objCategory)
        {
            bool result = _daoProduct.Insert(objCategory);
            if (result)
                clsCacheUtil.RemoveCacheWithPrefix("Category_");
            return result;
        }
        public bool Update(Category objCategory)
        {
            if (objCategory.CategoryID <= 0)
                return false;

            bool result = _daoProduct.Update(objCategory);
            if (result)
                clsCacheUtil.RemoveCacheWithPrefix("Category_");
            return result;
        }
        public Category GetByID(int _categoryID)
        {
            if (_categoryID <= 0)
                return null;
            string key = "Category_GetByID_" + _categoryID;
            Category result = clsCacheUtil.GetCache(key) as Category;
            if (result == null)
            {
                result = _daoProduct.GetByID(_categoryID);
                clsCacheUtil.SetCache(key, result);
            }
            return result;
            //return _daoProduct.GetByID(_categoryID);
        }
        public Category GetByProductID(int _productID)
        {
            if (_productID <= 0)
                return null;
            string key = "Category_GetByProductID_" + _productID;
            Category result = clsCacheUtil.GetCache(key) as Category;
            if (result == null)
            {
                result = _daoProduct.GetByProductID(_productID);
                clsCacheUtil.SetCache(key, result);
            }
            return result;
            //return _daoProduct.GetByID(_categoryID);
        }
        public CategoryCollection GetAllToControl()
        {
            string key = "Category_GetAllToControl";
            CategoryCollection result = clsCacheUtil.GetCache(key) as CategoryCollection;
            if (result == null)
            {
                result = _daoProduct.GetAllToControl();
                clsCacheUtil.SetCache(key, result);
            }
            return result;
            //return _daoProduct.GetAllToControl();
        }
        public Category GetCateForProduct(int categoryID, int productID)
        {
            string key = "Category_GetCateForProduct_" + categoryID + "_" + productID;
            Category result = clsCacheUtil.GetCache(key) as Category;
            if (result == null)
            {
                result = _daoProduct.GetCateForProduct(categoryID, productID);
                clsCacheUtil.SetCache(key, result);
            }
            return result;
            // return _daoProduct.GetCateForProduct(categoryID, productID);
        }
        public CategoryCollection GetByParentId(int parentId)
        {
            string key = "Category_GetByParentId_" + parentId;
            CategoryCollection result = clsCacheUtil.GetCache(key) as CategoryCollection;
            if (result == null)
            {
                result = _daoProduct.GetByParentId(parentId);
                clsCacheUtil.SetCache(key, result);
            }
            return result;
        }
        public string GetCategoryPathId(int categoryID)
        {
            string key = "Category_GetCategoryPathId_" + categoryID;
            string result = clsCacheUtil.GetCache(key) as string;
            if (result == null)
            {
                result = _daoProduct.GetCategoryPathId(categoryID);
                clsCacheUtil.SetCache(key, result);
            }
            return result;
        }
        public void DeleteVideoCategoryTree(int categoryID)
        {
            _daoProduct.DeleteVideoCategoryTree(categoryID);
            clsCacheUtil.RemoveCacheWithPrefix("Category_");
        }
        public void DeleteProductCategoryTree(int categoryID)
        {
          //  _daoProduct.DeleteProductCategoryTree(categoryID);
            _daoProduct.DeleteProductCategoryTree(categoryID);
            clsCacheUtil.RemoveCacheWithPrefix("Category_");
        }
        public void DeleteAreaCategoryTree(int categoryID)
        {
            _daoProduct.DeleteAreaCategoryTree(categoryID);
            clsCacheUtil.RemoveCacheWithPrefix("Category_");
           // _daoProduct.DeleteAreaCategoryTree(categoryID);
        }
    }

}